<template>
  <div id="globalSider">

    <a-layout-sider v-if="loginUserStore.loginUser.id" class="sider" width="200"
                    breakpoint="lg"
                    collapsed-width="0">
      <a-menu
        mode="inline"
        v-model:selectedKeys="current"
        :items="menuItems"
        @click="doMenuClick"
      />
    </a-layout-sider>
  </div>

</template>




<script setup lang="ts">
// 菜单列表
import { computed, h, ref, watchEffect } from 'vue'
import { useRouter } from 'vue-router'
import {
  PictureOutlined,
  UserOutlined,
  FileSearchOutlined,
  FireOutlined,
  UnorderedListOutlined,
  TeamOutlined, AppstoreOutlined, FileTextOutlined
} from '@ant-design/icons-vue'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'

import { message } from 'ant-design-vue'
const loginUserStore = useLoginUserStore()



const menuItems = [
  {
    key: '/user_question_submit',
    icon: () => h(UserOutlined),
    label: '我的提交',
    title: '我的提交',
  },
  {
    key: '/questions',
    icon: () => h(FileTextOutlined),
    label: '题库',
    title: '题库',
  },
  {
    key: '/question_submit',
    icon: () => h(FileSearchOutlined),
    label: '提交记录',
    title: '提交记录',
  },
]

const router = useRouter()

// 当前选中菜单
const current = ref<string[]>([])
// 监听路由变化，更新当前选中菜单,高亮菜单项
router.afterEach((to, from, failure) => {
  current.value = [to.path]
})


// 路由跳转事件
const doMenuClick = ({ key }: { key: string }) => {
  router.push(key)
}









</script>



<style scoped>
/* 侧边栏头部 */
.sider-header {
  padding: 20px 16px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #1890ff, #722ed1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
}

.header-text {
  flex: 1;
  min-width: 0;
}

.header-title {
  color: #262626;
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.header-subtitle {
  color: #8c8c8c;
  font-size: 12px;
  line-height: 1;
}

</style>
